package functiiTrigonometrice;

import functii.*;
import operator.*;
/**
 * @author Feri
 */
/**
 *  This class is the implementation of the arcsin() function. <br />
 * See <A href="https://sites.google.com/site/sabloanedeproiectare/refactoring" > Design Patterns Lab </A>
 */

public class Arcsin extends Functie{
	/**
	 * 
	 * @param aux1 
	 * @return Returns the value of arcsin(aux1).
	 */
	public static double calcul(double aux1){
		return Math.asin(aux1);
	}
	/**
	 * If the left son is not null returns arcsin(<i>left son</i>).
	 */
	public double calcul(){
		if (getfStang() == null)
			System.exit(1);
		return calcul(getfStang().calcul());
	}
	/**
	 * Returns the derived arcsin function.
	 */
	public String derivare(){
	if (getfStang() == null)
		System.exit(1);
	return Cat.concatTermens(getfStang().derivare(),"sqrt(1-" + getfStang().toString() + "^2)");
	}
	/**
	 * Returns the value of the derived arcsin function.
	 */
	public double calculDerivata(){
		if (getfStang() == null)
			System.exit(1);
		return Cat.Calcul(getfStang().calculDerivata(), Math.sqrt(1 - Math.pow(getfStang().calcul(), 2)));
	}
	/**
	 * Overrides the toString method.
	 */
	public String toString(){
		if (getfStang() == null)
			System.exit(1);
		return concatTermeni(getfStang().toString());
	}
	/**
	 * 
	 * @param aux1
	 * @return Same as concatTermeni, but it is static
	 */
	public static String concatTermens(String aux1){
		String aux;
		int nrP;
		nrP = aux1.charAt(0) == '(' ? 0 : 2;
		aux = "arcsin";
		if (nrP != 0) aux += "(";
		aux += aux1;
		if (nrP != 0) aux += ")";
		return aux;
	}
	/**
	 * 
	 * @param aux1 Auxiliary variable
	 * @return Concatenates "arcsin(" with the auxiliary variable
	 */
	public String concatTermeni(String aux1){
		String aux;
		int nrP;
		nrP = aux1.charAt(0) == '(' ? 0 : 2;
		aux = "arcsin";
		if (nrP != 0) aux += "(";
		aux += aux1;
		if (nrP != 0) aux += ")";
		return aux;
	}
	/**
	 * 
	 * @return Returns the calculated value
	 */
	public double calculeazaValoare() {
		return this.calcul();
	}
}
